package com.urbo.android.shortcutter;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;

public class Shortcut {
	//private static Shortcut instance = null;
	
	public Shortcut() {
	}

	public static void createShortcut(
			Context context, 
			String packageName, 
			String activityClass, 
			String shortcutTitle, 
			BitmapDrawable icon) {
		
		Intent shortcutIntent = new Intent();
		shortcutIntent.setClassName(packageName, activityClass);
		shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		//	shortcutIntent.putExtra("someParameter", "HelloWorld");
		Intent addIntent = new Intent();
		addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
		addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
		addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutTitle);
		addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon.getBitmap());
		context.sendBroadcast(addIntent);
		
	}
	
	public static void createSmsShortcut(
			Context context,
			String shortcutTitle, 
			BitmapDrawable icon,
			String smsNumber,
			String smsMessage) {
		
		Intent shortcutIntent = new Intent(Intent.ACTION_VIEW);         
		shortcutIntent.putExtra("address", smsNumber);
		shortcutIntent.putExtra("sms_body", smsMessage); 
		shortcutIntent.setType("vnd.android-dir/mms-sms");

		Intent addIntent = new Intent();
		addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
		addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
		addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutTitle);
		addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon.getBitmap());
		context.sendBroadcast(addIntent);
		
	}
	
	public static void createCallShortcut(
			Context context,
			String shortcutTitle, 
			BitmapDrawable icon,
			String phoneNumber) {
		
	
		Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:" + phoneNumber));         
		//shortcutIntent.putExtra("address", smsNumber);
		//shortcutIntent.putExtra("sms_body", smsMessage); 
		//shortcutIntent.setType("vnd.android-dir/mms-sms");

		Intent addIntent = new Intent();
		addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
		addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
		addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutTitle);
		addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon.getBitmap());
		context.sendBroadcast(addIntent);
		
	}
	
	public static void createEmailShortcut(
			Context context,
			String shortcutTitle, 
			BitmapDrawable icon,
			String emailAddress,
			String emailSubject,
			String emailText) {
		
		String emailAddressList[] = {emailAddress};
	    
		Intent shortcutIntent = new Intent(Intent.ACTION_SEND);  
		shortcutIntent.setType("plain/text");
		shortcutIntent.putExtra(Intent.EXTRA_EMAIL  , emailAddressList);   
		shortcutIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
		shortcutIntent.putExtra(Intent.EXTRA_TEXT, emailText);  
		
		//context.startActivity(shortcutIntent); //direct start of activity works fine

		Intent addIntent = new Intent();
		addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
		addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,  shortcutIntent);
		addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutTitle);
		addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon.getBitmap());
		context.sendBroadcast(addIntent);
	}
}
